using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;

namespace Open.Data.Persistence.SqlServer
{
	public class SqlCacheItem: CacheItem 
	{
		//Property variables
        private bool _isIdentity;
        private PropertyInfo _identity;

		public SqlCacheItem(Type type, SqlReflectionParser parser): base(type, parser)
		{
            _isIdentity = parser.IsIdentity;
            _identity = parser.PrimaryKey;
		}

        public bool IsIdentity
        {
            get
            {
                return _isIdentity;
            }
        }

        public PropertyInfo Identity
        {
            get
            {
                return _identity;
            }
        }

        public SqlIdentityAttribute GetIdentityAttribute()
        {
            if (Identity == null) return null;

            object[] attributes = PrimaryKey.GetCustomAttributes(false);
            foreach (Attribute attr in attributes)
            {
                if (attr is SqlIdentityAttribute) return attr as SqlIdentityAttribute;
            }

            return null;
        }
	}
}
